import React from 'react'
import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom'
import page from './page'

const Router = () => {

    const mapRouter = (routers) => {
        const newRouters = routers.map((item, idx) => {
            return item.path ? <Route path={item.path} element={item.element} key={idx}>
                {
                    item.children && mapRouter(item.children)
                }
            </Route> : <Route path={item.from} element={<Navigate to={item.to} />} key={idx} />
        })

        return newRouters
    };

    return (
        <BrowserRouter>
            <Routes>
                {mapRouter(page)}
            </Routes>
        </BrowserRouter>
    )
}

export default Router
